﻿namespace Tequila.Phone.Sharing.Twitpic
{
    /// <summary>
    /// Twitpic response.
    /// </summary>
    public class TwitpicResponse
    {
        /// <summary/>
        public readonly int UserId; // like 11111

        /// <summary/>
        public readonly string MediaId; // like abc123

        /// <summary/>
        public readonly string MediaUrl; // Something like this http://twitpic.com/abc123

        /// <summary/>
        public readonly string MiniImage; // Mini Thumbnail URL

        /// <summary/>
        public readonly string ThumbImage; // Thumbnail URL

        /// <summary/>
        public readonly bool IsSuccess; // True = Success | False= Fail

        /// <summary/>
        public readonly TwitpicResponseErrorType ErrorCode;

        // err_code= 1001 - Invalid twitter username or passwor
        // err_code= 1002 - Image not found
        // err_code= 1003 - Invalid image type
        // err_code= 1004 - Image larger than 4MB 

        /// <summary/>
        public readonly string ErrorMessage; //Will contain the sorry excuse for not doing ur job ;-)

        /// <summary>
        /// Initializes new instance of class. To be called, when Method = UploadAndPost.
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="mediaid"></param>
        /// <param name="mediaurl"></param>
        public TwitpicResponse(int userid, string mediaid, string mediaurl)
        {
            UserId = userid;
            MediaId = mediaid;
            MediaUrl = mediaurl;
            MiniImage = "http://twitpic.com/show/mini/" + mediaid;
            ThumbImage = "http://twitpic.com/show/thumb/" + mediaid;
            IsSuccess = true;
            ErrorCode = TwitpicResponseErrorType.None;
            ErrorMessage = "";
        }

        /// <summary>
        /// Initializes new instance of class. To be called, when Method = Upload.
        /// </summary>
        /// <param name="mediaid"></param>
        /// <param name="mediaurl"></param>
        public TwitpicResponse(string mediaid, string mediaurl)
        {
            UserId = 0;
            MediaId = mediaid;
            MediaUrl = mediaurl;
            MiniImage = "http://twitpic.com/show/mini/" + mediaid;
            ThumbImage = "http://twitpic.com/show/thumb/" + mediaid;
            IsSuccess = true;
            ErrorCode = TwitpicResponseErrorType.None;
            ErrorMessage = "";
        }

        /// <summary>
        /// Initializes new instance of class. To be called, when error occurs.
        /// </summary>
        /// <param name="errorcode"></param>
        /// <param name="message"></param>
        public TwitpicResponse(int errorcode, string message)
        {
            UserId = -1;
            MediaId = "";
            MediaUrl = "";
            MiniImage = "";
            ThumbImage = "";
            IsSuccess = false;
            switch (errorcode)
            {
                case 1001:
                    ErrorCode = TwitpicResponseErrorType.InvalidTwitterUserNameOrPassword;
                    break;
                case 1002:
                    ErrorCode = TwitpicResponseErrorType.ImageNotFound;
                    break;
                case 1003:
                    ErrorCode = TwitpicResponseErrorType.InvalidImageType;
                    break;
                case 1004:
                    ErrorCode = TwitpicResponseErrorType.ImageTooLarge;
                    break;
            }

            ErrorMessage = message;
        }

        /// <summary>
        /// Initializes new instance of class. To be called, when internal error occurs.
        /// </summary>
        /// <param name="message"></param>
        public TwitpicResponse(string message)
        {
            IsSuccess = false;
            ErrorCode = TwitpicResponseErrorType.Unexpected;
            ErrorMessage = message;
        }
    }
}